#!/bin/bash
#========================时间设置============================
if [[ $date = "" ]]; then 
    export date=$(date +%Y%m%d)
fi

export cur_date=$date
export y_date=$(date '+%Y%m%d' -d '-1 day '$date'')

#数据过期时间
EXPIRE_DAYS=14 

# 重要环境变量.
export JAVA_HOME=/home/hadoop/hadoop_hbase/jdk1.6.0_23
export HADOOP_HOME=/home/hadoop/hadoop_hbase/hadoop/current
export HBASE_HOME=/home/hadoop/hadoop_hbase/hbase/current
export HADOOP_STREAMING_JAR=$HADOOP_HOME/contrib/streaming/*.jar

HADOOP=$HADOOP_HOME/bin/hadoop
HADOOP_CONF=
HADOOP_CLASSPATH=
HBASE_CONFIG_LOADER_OPT="-conf $HBASE_HOME/conf/hbase-default.xml \
                         -conf $HBASE_HOME/conf/hbase-site.xml"

CLICKS_HDFS=hftp://hdpnn:50070

# CLASSPATH 设置.

for f in $HBASE_HOME/hbase*.jar; do
    if [[ $f = *sources.jar || $f = *tests.jar ]]; then
        :
    elif [[ -f $f ]]; then
        HADOOP_CLASSPATH=$HADOOP_CLASSPATH:$f
    fi
done

for f in $HBASE_HOME/lib/*.jar; do
    if [[ $f = *zookeeper*jar ]]; then
        HADOOP_CLASSPATH=$HADOOP_CLASSPATH:$f
    fi
done

HADOOP_CLASSPATH=$HADOOP_CLASSPATH:$HBASE_HOME/conf
HADOOP_CLASSPATH=$(echo $HADOOP_CLASSPATH | sed 's/^://')

export HADOOP_CLASSPATH

function libjars()
{
    echo "$@" | sed 's/:/,/g'
}

# test if a string list contains a string
function contains() {
    local value=$1
    local key=$2
    local found=1
    local ifs=$IFS
    IFS=","
    for v in $value; do
        if [ "$v" == "$key" ]; then
            found=0
            break
        fi
    done
    IFS=$ifs
    return $found
}

function hadoop() {
    if [ -n "$HADOOP_CONF" ]; then
        $HADOOP --config $HADOOP_CONF "$@"
    else
        $HADOOP "$@"
    fi
}

function htouch() {
    hadoop fs -touchz "$@"
}

function hexist() {
    hadoop fs -test -e "$@"
}

function hrmr() {
    if hexist "$@"; then
        hadoop fs -rmr "$@"
    fi
}

function hmkdir() {
    if ! hexist "$@"; then
        hadoop fs -mkdir "$@"
    fi
}

function hrm() {
    if hexist "$@"; then
        hadoop fs -rm "$@"
    fi
}

function hput() {
    local input=$1
    local output=$2
    hrmr $output
    hadoop dfs -put $input $output
}

function hdus() {
    if hexist "$@"; then
        hadoop dfs -dus "$@" | awk '{print $2}'
    else
        echo 0
    fi
}

function transfer() {
    local input=$1
    local output=$2
    hadoop distcp -m 10 $CLICKS_HDFS/$input $output
}

# Yunti configuration
CLICKS_HADOOP=/home/a/libexec64/hadoop/hadoop-0.19.0/bin/hadoop
CLICKS_HADOOP_CONF=

function clicks_hadoop() {
    if [ -n "$CLICKS_HADOOP_CONF" ]; then
        $CLICKS_HADOOP --config $CLICKS_HADOOP_CONF "$@"
    else
        $CLICKS_HADOOP "$@"
    fi
}

function clicks_hexist() {
    clicks_hadoop fs -test -e "$@"
}

# Local variables:
# mode: shell-script
# sh-basic-offset: 2
# sh-indentation: 2
# End: